package com.ruoyi.exam.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.ExamCalendar;
import com.ruoyi.exam.service.IExamCalendarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 校历信息Controller
 * 
 * @author ruoyi
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/exam/calendar")
public class ExamCalendarController extends BaseController
{
    @Autowired
    private IExamCalendarService examCalendarService;

    /**
     * 查询校历信息列表
     */
    @PreAuthorize("@ss.hasPermi('exam:calendar:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamCalendar examCalendar)
    {
        startPage();
        List<ExamCalendar> list = examCalendarService.selectExamCalendarList(examCalendar);
        return getDataTable(list);
    }

    /**
     * 导出校历信息列表
     */
    @PreAuthorize("@ss.hasPermi('exam:calendar:export')")
    @Log(title = "校历信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamCalendar examCalendar)
    {
        List<ExamCalendar> list = examCalendarService.selectExamCalendarList(examCalendar);
        ExcelUtil<ExamCalendar> util = new ExcelUtil<ExamCalendar>(ExamCalendar.class);
        util.exportExcel(response, list, "校历信息数据");
    }

    /**
     * 获取校历信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:calendar:query')")
    @GetMapping(value = "/{calendarId}")
    public AjaxResult getInfo(@PathVariable("calendarId") Long calendarId)
    {
        return success(examCalendarService.selectExamCalendarByCalendarId(calendarId));
    }

    /**
     * 新增校历信息
     */
    @PreAuthorize("@ss.hasPermi('exam:calendar:add')")
    @Log(title = "校历信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamCalendar examCalendar)
    {
        return toAjax(examCalendarService.insertExamCalendar(examCalendar));
    }

    /**
     * 修改校历信息
     */
    @PreAuthorize("@ss.hasPermi('exam:calendar:edit')")
    @Log(title = "校历信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamCalendar examCalendar)
    {
        return toAjax(examCalendarService.updateExamCalendar(examCalendar));
    }

    /**
     * 删除校历信息
     */
    @PreAuthorize("@ss.hasPermi('exam:calendar:remove')")
    @Log(title = "校历信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{calendarIds}")
    public AjaxResult remove(@PathVariable Long[] calendarIds)
    {
        return toAjax(examCalendarService.deleteExamCalendarByCalendarIds(calendarIds));
    }
}
